function goCalc() {
    var e, n, a, l, i, t;
    return e = $("#chejia").val(),
    n = $("#shoufu").val(),
    a = $("#lilv").val(),
    l = $("#qixian").val(),
    je = e * (1 - .1 * n) * 1e4,
    console.log(je),
    i = debx(je, a, l, 1, 1),
    t = debj(je, a, l, 1, 1),
    {
        errno: 0,
        data: {
            debx_dkje: fmoney(je, 2),
            debx_dkqx: l,
            debx_myhk: fmoney(i.yhk, 2),
            debx_zflx: fmoney(i.zlx, 2),
            debx_hkze: fmoney(i.hkze, 2),
            debj_dkje: fmoney(je, 2),
            debj_dkqx: l,
            debj_syhk: fmoney(t.syhk, 2),
            debj_mydj: fmoney(t.mydj, 2),
            debj_zflx: fmoney(t.zlx, 2),
            debj_hkze: fmoney(t.hkze, 2)
        }
    }
}
function fmoney(e, n) {
    n = n > 0 && 20 >= n ? n: 2,
    e = parseFloat((e + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
    var a = e.split(".")[0].split("").reverse(),
    l = e.split(".")[1];
    for (t = "", i = 0; i < a.length; i++) t += a[i] + ((i + 1) % 3 == 0 && i + 1 != a.length ? ",": "");
    return t.split("").reverse().join("") + "." + l
}
function debx(e, n, a, l, t) {
    a = parseInt(a),
    e = parseFloat(e),
    n = parseFloat(n),
    l = parseInt(l),
    t = parseInt(t),
    ylv = 2 == l ? .01 * n: n / 12 * .01;
    var o = Math.pow(1 + ylv, a),
    r = e * ylv * (o / (o - 1)),
    c = r * a,
    v = c - e,
    h = new Object;
    if (h.zlx = v, h.hkze = c, h.yhk = r, 1 == t) {
        var y = e,
        f = [];
        for (i = 1; a >= i; i++) {
            var s = y * ylv,
            u = r - s;
            y -= u;
            var d = new Object;
            d.bh = i,
            d.ylx = s,
            d.ybj = u,
            d.ye = y,
            f[i - 1] = d
        }
        h.xx = f
    }
    return h
}
function debj(e, n, a, l, t) {
    a = parseInt(a),
    e = parseFloat(e),
    n = parseFloat(n),
    l = parseInt(l),
    t = parseInt(t),
    ylv = 2 == l ? .01 * n: n / 12 * .01;
    var o = 0,
    r = e / a,
    c = new Object;
    c.ybj = r;
    var v = e,
    h = [];
    for (i = 1; a >= i; i++) {
        yhk = e / a + (e - e * (i - 1) / a) * ylv,
        1 == i && (c.syhk = yhk),
        2 == i && (c.mydj = c.syhk - yhk),
        o += yhk,
        ylx = yhk - r,
        v -= r;
        var y = new Object;
        y.bh = i,
        y.ylx = ylx,
        y.yhk = yhk,
        y.ye = v,
        h[i - 1] = y
    }
    return 1 == t && (c.xx = h),
    c.zlx = o - e,
    c.hkze = o,
    c
}
$(function() {
    function e() {
        var e = $("#qixian").val(),
        n = $("#lilv-sel").val();
        $("#lilv").val(RCal.getSdLilv(e, n))
    }
    return window.location.hash ? void(window.location.hash = "") : (MW.define("calc-input",
    function(e) {
        e.active = function() {
            $.log({
                page_name: pagename
            }),
            $("[data-event='tap:cal']").on("click",
            function() {
                var e = goCalc();
                0 == e.errno && (MW.goTo("#/calc_result"), MW.getView("calc_result").model("calc_result", e))
            })
        },
        e.event = {}
    }), MW.define("calc_result",
    function(e) {
        e.active = function() {}
    }), $("#lilv-sel, #qixian").on("change",
    function() {
        e()
    }), $("#lilv-sel, #qixian").on("focus",
    function() {
        e()
    }), $("#xingzhi").on("change",
    function() {
        "1" == $(this).val() ? ($("#shoufu").val("3"), $("#shoufu-bar").html("3成").attr("value", 3)) : ($("#shoufu").val("6"), $("#shoufu-bar").html("6成").attr("value", 6))
    }), void e())
});